package org.tea.inventory.db.service;

import com.github.pagehelper.PageHelper;
import org.tea.inventory.db.dao.ContributeMapper;
import org.tea.inventory.db.domain.Contribute;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class ContributeService {

    @Resource
    private ContributeMapper contributeMapper;


    /**
     * 分页获取 投稿 列表
     */
    public List<Contribute> querySelective(Contribute contribute, int page, int limit, String sort) {

        List<Contribute> lstContribute = null;
        PageHelper.startPage(page, limit);
        lstContribute = contributeMapper.selectByExample(contribute);

        return lstContribute;
    }

    /**
     * 获取投稿列表数量
     */
    public Integer countSelective(Contribute contribute) {

        int total = (int)contributeMapper.countByExample(contribute);
        return total;
    }

    /**
     * 获取指定id的投稿详情
     */
    public Contribute findById(Integer id) {

        Contribute contribute = contributeMapper.selectByPrimaryKey(id);
        return contribute;
    }

    /**
     * 录入投稿信息
     */
    public void add(Contribute contribute) {
        contributeMapper.insertSelective(contribute);
    }

    /**
     * 更新投稿信息
     */
    public void update(Contribute contribute) {
        contributeMapper.updateByPrimaryKeySelective(contribute);
    }
    
    /**
     * 查询最后一次上传的投稿
     * @return
     */
    public Map findLastContribute() {
    	return contributeMapper.selectLastContribute();
    }

    /**
     * 删除投稿信息
     */
    public void delete(int id) {
        contributeMapper.deleteByPrimaryKey(id);
    }
}
